package com.zy.gmall0401.user.controller;


import com.zy.gmall0401.bean.UserInfo;
import com.zy.gmall0401.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    //    @Autowired
    UserService userService;

    @PostMapping("addUser")
    public String addUser(UserInfo userInfo) {
        userService.addUser(userInfo);
        return "success";
    }

    @GetMapping("allUser")
    public List<UserInfo> getAllUser() {
        return userService.getUserInfoListAll();
    }

    @GetMapping("userInfo")
    public UserInfo getUser(String id) {
        return userService.getUserInfo(id);
    }

    @PostMapping("delUser")
    public String deleteUserid(String id) {
        userService.delUserid(id);
        return "success";
    }

    @PostMapping("updateUser")
    public String updateUser(UserInfo userInfo) {
        userService.updateUser(userInfo);
        return "success";

    }

    @PostMapping("updateUserByName")
    public String updateUserByName(UserInfo userInfo) {
        userService.updateUserByName(userInfo.getName(), userInfo);
        return "success";
    }
}
